package com.ruoyi.web.entity.db;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.core.entity.BaseMap;
import lombok.Data;

import java.util.List;

@Data
public class UpdateCreator extends Creator {

    private List<ColumnInfo> columns;

    public UpdateCreator() {
    }

    public UpdateCreator(BaseMap queryData) {
        super(queryData);
    }

    public static <T> void set(UpdateWrapper<T> uw, List<ColumnInfo> columns) {
        if (columns != null && columns.size() > 0) {
            for (ColumnInfo column : columns) {
                uw.set(resolveColumnName(column.getCloumnName()), column.getValue());
            }
        }
    }


    @Data
    public static class ColumnInfo {
        private String cloumnName;
        private Object value;

        public ColumnInfo(String cloumnName, Object value) {
            this.cloumnName = cloumnName;
            this.value = value;
        }
    }

}
